which it is most naturally
described.
William James
a) friendb) ios::left, ios::right, and ios::internal.
c) streams.
d) setiosflags, resetiosflags.
e) iostream.h.
f) setf, unsetf.
g) strstream.h
h) iomanip.h.
i) fstream.h.
j) endl.
k) stdiostream.h.
l) write.m) istream.
n) cerr or clog.
o) ostream.
p) <<.
q) cin, cout, cerr, and clog.
r) >>.
s) oct, hex, dec.
t) six digits of precision.
u) ios::showpos.
a) cout << "Enter your name: ";b) cout.setf(ios::uppercase);
c) cout << (void *) string;
d) cout.setf(ios::scientific, ios::floatfield);
e) cout << integerPtr;
f) cout << setiosflags(ios::showbase);
g) cout << *floatPtr;
h) cout.fill( '*' );
cout << setfill( '*' );
i) cout.put( 'O' ).put( 'K' );
j) cin.peek();
k) c = cin.get()cin.get( c );
l) cin.ignore( 6 );
m) cin.read( line, 50 );
n) cin.get( name, 10, '.' );
cin.getline( name, 10, '.' );
o) cout.write( line, cin.gcount() );
p) cout.flush();
cout << flush;
q) cout << 124 << 18.376 << 'Z' << 1000000 << "String";
r) cout << cout.precision();
s) cin >> months >> percentageRate;t) cout << setprecision( 3 ) << 1.92 << '\ '
<< 1.925 << '\ ' << 1.9258;
u) cout << oct << 100 << hex << 100 << dec << 100;
v) cout << 100 << setbase( 8 ) << 100 << setbase( 16 ) << 100;
w) cout << setw( 10 ) << 1234;
x) cin.get( line, 20, 'z' );
y) cout << setw( x ) << setprecision( y ) << 87.4573;
cout << int('c');
cout << '"' << "A string in quotes" << '"';cout << "\\"A string in quotes\\"";
a) 12345**123
123
b) $$$$$10000
c) 1024.988
d) 0143
0x63
e) 100000
+100000
f) 4.45e+02
________.
c) Input/output in C++ occurs as _________ of bytes.
d) Parameterized stream manipulators ________ and ________ can be used
to set and reset format state flags.
e) Most C++ programs should include the _________ header file that contains
basic information required for all stream I/O operations.
________ stream object.
o) Output operations are supported by the ________ class.
p) The symbol for the stream-insertion operator is ________.
q) The four objects that correspond to the standard devices on the system
include
________, ________, ________, and ________.
r) The symbol for the stream-extraction operator is ________.
a) cout << "Value of x <= y is: " << x <= y;b) The following statement should print the integer value of ' c'.
cout << 'c';c) cout << ""A string in quotes"";
a) cout << "12345" << endl;cout.width( 5 );
cout.fill( '*' );
cout << 123 << endl << 123;
b) cout << setw( 10 ) << setfill( '$' ) << 10000;
c) cout << setw( 8 ) << setprecision( 3 ) << 1024.987654;
d) cout << setiosflags( ios::showbase ) << oct << 99
<< endl << hex << 99;
e) cout << 100000 << endl
<< setiosflags( ios::showpos ) << 100000;f) cout << setw( 10 ) << setprecision( 2 ) <<
<< setiosflags( ios::scientific ) << 444.93738;
celsius = 5.0 / 9.0 * ( fahrenheit - 32 );to perform the calculation. The output should be printed in two right-justified columns, and the Celsius temperatures should be preceded by a sign for both positive and negative values.
3 + 8ic)
cin >> grade;Note that the stream-extraction operation is "smart enough" to "know" what the type of the data is. Assuming that grade has been properly declared, no additional type information needs to be specified for use with the stream-extraction operator (as is the case, incidentally, in C-style I/O).
cout << grade;Note that the stream-insertion operator is "smart enough" to "know" the type of grade (assuming it has been properly declared), so no additional type information needs to be specified for use with the stream-insertion operator.
cout << flush;Stream manipulators are discussed in detail in Section 11.6.
cout << "Hello" << endl;.
( ( ( cout << "47 plus 53 is " )i.e., << associates from left to right. This kind of cascading of stream-insertion operators is allowed because the overloaded << operator returns a reference to its left-operand object, i.e., cout. Thus the leftmost parenthesized expression<< ( 47 + 53 ) ) << endl );
( cout << "47 plus 53 is " )outputs the specified character string and returns a reference to cout. This allows the middle parenthesized expression to be evaluated as
( cout << ( 47 + 53 ) )which outputs the integer value 100 and returns a reference to cout. The rightmost parenthesized expression is then evaluated as
cout << endlwhich outputs a newline, flushes cout, and returns a reference to cout. This last return is not used.
cout.put( 'A' );which displays A on the screen. Calls to put may be cascaded as in
cout.put( 'A' ).put( '\n' );which outputs the letter A followed by a newline character. As with <<, the preceding statement executes in this manner because the dot operator (.) associates from left to right and the put member function returns a reference to the object through which the put call is
char buffer[] = "HAPPY BIRTHDAY";outputs the first 10 bytes of buffer (including null characters that would cause output with cout and << tocout.write( buffer, 10 );
cout.write( "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 10 );displays the first 10 characters of the alphabet.
*********************z.
9.99E+04.
long previousFlagSettings =The setf member function with two long arguments as incout.setf( ios::showpoint | ios::showpos );
cout.setf( ios::left, ios::adjustfield );first clears the bits of ios::adjustfield and then sets the ios::left flag. This version of setf is used with the bit fields associated with ios::basefield (represented by ios::dec, ios::oct, and ios::hex), ios::floatfield
cin.eof()returns true if end-of-file has been encountered on cin, and false otherwise.
cin.clear();clears cin and sets goodbit for the stream. The statement
cin.clear(ios::failbit)actually sets the failbit. The user might want to do this when performing input on cin with a user-defined type and encountering a problem. The name clear seems inappropriate in this context, but it is correct.
cin.tie( &cout );ties cout (an ostream) to cin (an istream). Actually, this particular call is redundant because C++ performs this operation automatically to create a user's standard input/output environment. The user would, however, explicitly tie together other istream/ostream pairs. To untie an input stream, inputStream, from an output stream, use the call
inputStream.tie( 0 );